package kr.pe.mkseo.data;

import java.util.List;
import java.util.Map;

import com.google.common.collect.Maps;

public class Category {
	
	private static Map<Integer, Category> map_ = Maps.newHashMap();
	private int key_;
	private String name_;
	private String desc_;
	
	private Category(int key, String name, String desc) {
		key_ = key;
		name_ = name;
		desc_ = desc;
	}
	
	public static Category CreateCategory(String name, String desc) {
		int key = CreateNewKey();
		Category c = new Category(key, name, desc);
		map_.put(key, c);
		return c;
	}
	
	public void DeleteCategory(Category c) {
		map_.remove(c.GetKey());
	}
	
	/**
	 * Load specified category. Used internally, for example, to load category
	 * data from file.
	 * @param data Category data of (key, name, description) list.
	 */
	static void LoadCategory(List<Category> data) {
		for (Category c: data) {
			map_.put(c.GetKey(), c);
		}
	}
	

	private static int CreateNewKey() {
		int max_key = Integer.MIN_VALUE;
		for (int k: map_.keySet()) {
			max_key = Math.max(max_key, k);
		}
		return max_key + 1;
	}
	
	private int GetKey() {
		return key_;
	}

	public String GetName() {
		return name_; 
	}

	public String GetDescription() {
		return desc_;
	}

	public static int Size() {
		return map_.size();
	}
}
